<template>
  <div id="app" @mousemove="moveEvent" @click="moveEvent">
    <router-view />
  </div>
</template>

<script>
export default {
  name: 'App',
  data() {
    return {
      timmer: null
    }
  },
  methods: {
    moveEvent: function() {
      const path = ['/login']
      if (!path.includes(this.$route.path)) {
        clearTimeout(this.timmer)
        this.init()
      }
    },
    init: function() {
      this.timmer = setTimeout(() => {
        this.$alert('您已15分钟未进行操作，请重新登录', '警告', {
          confirmButtonText: '确定',
          callback: action => {
            this.logout()
          }
        })
      }, 1000 * 60 * 15)// 20*0.5  10seconds
    },
    async logout() {
      await this.$store.dispatch('user/logout')
      this.$router.push(`/login?redirect=${this.$route.fullPath}`)
    }
  }
}

</script>
